package com.xbai.spark.core.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * take(n) 算子
  * 作用：返回一个由RDD的前n个元素组成的数组
  * @author xbai
  * @Date 2020/12/31
  */
object Spark05_Take {

  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("reduce")
    val sc = new SparkContext(conf)

    val rdd: RDD[Int] = sc.parallelize(1 to 10)
    val array: Array[Int] = rdd.take(3)
    array.foreach(println)
    sc.stop()
  }
}
